home *** CD-ROM | disk | FTP | other *** search
/ E.M.Computergraphic Phase 4 / Phase 4 - Desktop Video Dreams (E. M. Computergraphic)(1996).iso / utilities / imagestudio / rexx / batchprocess.isrx < prev    next >
Text File  |  1996-01-17  |  8KB  |  308 lines

  1. /* ImageStudio ARexx script **************************************/
  2.  
  3. /* Allow commands to return results */
  4.  
  5. options results
  6.  
  7. /* On error, goto ERROR:. Comment out this line if you wish to */
  8. /* perform your own error checking. */
  9.  
  10. signal on error
  11.  
  12. /* BEGIN PROGRAM *************************************************/
  13.  
  14. /* Warn the user if they are about to overwrite their current project */
  15.  
  16. IMAGEINFO_GET STEM imageinfo.
  17.  
  18. if imageinfo.changed == 1 then
  19.     REQUEST_MESSAGE TEXT '"Project has changed, continue?"',
  20.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  21.  
  22. /* Choose source files */
  23.  
  24. REQUEST_MULTIFILE TITLE '"Choose source files..."' STEM srcfiles.
  25.  
  26. /* Use separate destination directory ? */
  27.  
  28. REQUEST_MESSAGE TEXT '"Use different destination directory?"',
  29.     BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  30.  
  31. if result == 1 then
  32.     REQUEST_DIR TITLE '"Choose destination directory..."' VAR destdir
  33. else
  34.     destdir = ':NONE:'
  35.  
  36. REQUEST_LIST TITLE '"Choose output format..."' STRINGS,
  37.     '"IFF-ILBM"',
  38.     '"BMP"',
  39.     '"EPS"',
  40.     '"GIF"',
  41.     '"JPEG"',
  42.     '"PCX"',
  43.     '"Targa"' STEM saveformat.
  44.  
  45. /* Set up a blank ARGS string, which we can add to */
  46.  
  47. saveargs = 'ARGS "'
  48.  
  49. /* Get any IFF-ILBM args ? */
  50.  
  51. if saveformat.string == 'IFF-ILBM' then do
  52.     /* Get a subformat */
  53.  
  54.     REQUEST_MESSAGE TEXT '"Choose ILBM format..."' BUTTONTEXT,
  55.         '"As buffer|HAM6|HAM8|EHB|Cancel"' AUTOCANCEL
  56.  
  57.     /* Store subformat */
  58.  
  59.     if result == 2 then
  60.         saveargs = saveargs||'SUBFORMAT HAM6'
  61.     else if result == 3 then
  62.         saveargs = saveargs||'SUBFORMAT HAM8'
  63.     else if result == 4 then
  64.         saveargs = saveargs||'SUBFORMAT EHB'
  65.  
  66.     /* Get the dither if not saving as buffer */
  67.  
  68.     if result ~= 1 then do
  69.         REQUEST_MESSAGE TEXT '"Choose ILBM dither..."' BUTTONTEXT,
  70.             '"None|Floyd-Steinberg|Cancel"' AUTOCANCEL
  71.  
  72.         /* Store the dither */
  73.  
  74.         if result == 2 then
  75.             saveargs = saveargs||' DITHER FS'
  76.  
  77.         end
  78.  
  79.     /* Ask whether should set screenmode of images */
  80.  
  81.     REQUEST_MESSAGE TEXT '"Set screenmode of images?"',
  82.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  83.  
  84.     if result == 1 then do
  85.         setscreenmode = 1
  86.  
  87.         REQUEST_SCREENMODE STEM screenmode.
  88.  
  89.         imagescreenmode = screenmode.modeid
  90.  
  91.         end
  92.     else
  93.         setscreenmode = 0
  94.     end
  95. else if saveformat.string == 'EPS' then do
  96.     /* Get the DPI of the image */
  97.  
  98.     REQUEST_STRING TEXT1 '"Enter the DPI resolution of"',
  99.         TEXT2 '"the EPS files to be saved:"',
  100.         STRING 300 VAR dpiinfo
  101.  
  102.     saveargs = saveargs||dpiinfo
  103.  
  104.     /* Ask whether to save as colour or greyscale */
  105.  
  106.     REQUEST_MESSAGE TEXT '"Greyscale or colour EPS?"' BUTTONTEXT,
  107.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  108.  
  109.     if result == 2 then
  110.         saveargs = saveargs||' COLOUR'
  111.  
  112.     end
  113. else if saveformat.string == 'JPEG' then do
  114.     /* Get the DPI of the image */
  115.  
  116.     REQUEST_STRING TEXT1 '"Enter the JPEG quality setting"',
  117.         TEXT2 '"for the files to be saved."',
  118.         TEXT3 '"(Valid values 25 to 100):"',
  119.         STRING 75 VAR qualityinfo
  120.  
  121.     saveargs = saveargs||qualityinfo
  122.  
  123.     /* Ask whether to save as colour or greyscale */
  124.  
  125.     REQUEST_MESSAGE TEXT '"Greyscale or colour JPEG?"' BUTTONTEXT,
  126.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  127.  
  128.     if result == 1 then
  129.         saveargs = saveargs||' GREYSCALE'
  130.  
  131.     end
  132.  
  133. /* We may or may not have created an ARGS string. If we have, lets */
  134. /* finish it off, else lets delete it */
  135.  
  136. if saveargs == 'ARGS "' then
  137.     saveargs = ''
  138. else
  139.     saveargs = saveargs||'"'
  140.  
  141. /* Rename filenames ? */
  142.  
  143. REQUEST_MESSAGE TEXT '"Rename filenames ?"' BUTTONTEXT,
  144.     '"Yes|No|Cancel"' AUTOCANCEL
  145.  
  146. if result == 1 then do
  147.     /* Set the rename files */
  148.  
  149.     renamefiles = 1
  150.  
  151.     /* Get the rename pattern */
  152.  
  153.     REQUEST_STRING TEXT1 '"Choose the filename extension"',
  154.         TEXT2 '"for example: .pcx .ilbm"',
  155.         TEXT3 '"would rename all PCX files to ILBM"',
  156.         STRING '". .'||saveformat.string||'"',
  157.         VAR renamestring
  158.     end
  159. else
  160.     renamefiles = 0
  161.  
  162. /* If we're renaming, we should ask if they want the source file */
  163. /* deleted. If we're not renaming, we should warn the user that */
  164. /* the source file will be overwritten. */
  165.  
  166. if renamefiles == 1 then do
  167.     REQUEST_MESSAGE TEXT '"Delete source files ?"',
  168.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  169.  
  170.     if result == 1 then
  171.         deletesource = 1
  172.     else
  173.         deletesource = 0
  174.     end
  175. else if renamefiles == 0 & destdir == ':NONE:' then
  176.     REQUEST_MESSAGE TEXT '"WARNING : Source files will\nbe overwritten."',
  177.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  178.  
  179. /* Ask user for process(s) to apply to image before saving out */
  180.  
  181. REQUEST_STRING TITLE '"Enter processes to apply..."',
  182.     TEXT1 '"Enter the processes to apply before"',
  183.     TEXT2 '"saving out the image (separate "',
  184.     TEXT3 '"commands with semi-colon ;)"' VAR process
  185.  
  186. /* Loop around and convert all the files */
  187.  
  188. do l = 0 to (srcfiles.files.count - 1)
  189.     /* Open the file */
  190.  
  191.     OPEN FILE '"'srcfiles.files.l'"' FORCE
  192.  
  193.     /* If you wish to customize this macro to perform any operations */
  194.     /* on the image before saving it out (e.g. resizing, colour */
  195.     /* reduction etc...), add the commands here */
  196.  
  197.     interpret process
  198.  
  199.     /* Set the screenmode if neccessary */
  200.  
  201.     if setscreenmode == 1 then
  202.         IMAGEINFO_SET MODEID imagescreenmode
  203.  
  204.     /* Create the output filename */
  205.  
  206.     if destdir ~= ':NONE:' then do
  207.         /* Get the filepart of the source filename */
  208.  
  209.         FILE_SPLIT FILE '"'srcfiles.files.l'"' STEM filesplit.
  210.  
  211.         /* Create the destfile */
  212.  
  213.         FILE_JOIN PATHPART '"'destdir'"',
  214.             FILEPART '"'filesplit.filepart'"' VAR 'destfile'
  215.  
  216.         end
  217.     else
  218.         destfile = srcfiles.files.l
  219.  
  220.     /* Rename file ? */
  221.  
  222.     if renamefiles == 1 then 
  223.         FILE_RENAME FILE '"'destfile'"' renamestring,
  224.             VAR 'destfile'
  225.  
  226.     /* Save the fileout in the new format */
  227.  
  228.     SAVE FILE '"'destfile'"' FORMAT '"'saveformat.string'"',
  229.         saveargs FORCE
  230.  
  231.     /* Delete source file (and icon) if required */
  232.  
  233.     if renamefiles == 1 & deletesource == 1 then do
  234.         /* Make sure hasn't been renamed to same name */
  235.  
  236.         if upper(srcfiles.files.l) == upper(destfile) then
  237.             break
  238.  
  239.         address command 'delete <NIL: >NIL: "'||srcfiles.files.l||'"'
  240.  
  241.         if exists(srcfiles.files.l||'.info') == 1 then
  242.             address command 'delete <NIL: >NIL: "'||,
  243.                 srcfiles.files.l||'.info"'
  244.         end
  245.     end
  246.  
  247.  
  248. /* END PROGRAM ***************************************************/
  249.  
  250. exit
  251.  
  252. /* On ERROR */
  253.  
  254. ERROR:
  255.  
  256. /* If we get here, either an error occurred with the command's */
  257. /* execution or there was an error with the command itself. */
  258. /* In the former case, rc2 contains the error message and in */
  259. /* the latter, rc2 contains an error number. SIGL contains */
  260. /* the line number of the command which caused the jump */
  261. /* to ERROR: */
  262.  
  263. if datatype(rc2,'NUMERIC') == 1 then do
  264.     /* See if we can describe the error with a string */
  265.  
  266.     select
  267.         when rc2 == 103 then
  268.             err_string = "ERROR 103, "||,
  269.                 "out of memory at line "||SIGL
  270.         when rc2 == 114 then
  271.             err_string = "ERROR 114, "||,
  272.                 "bad command template at line "||SIGL
  273.         when rc2 == 115 then
  274.             err_string = "ERROR 115, "||,
  275.                 "bad number for /N argument at line "||SIGL
  276.         when rc2 == 116 then
  277.             err_string = "ERROR 116, "||,
  278.                 "required argument missing at line "||SIGL
  279.         when rc2 == 117 then
  280.             err_string = "ERROR 117, "||,
  281.                 "value after keywork missing at line "||SIGL
  282.         when rc2 == 118 then
  283.             err_string = "ERROR 118, "||,
  284.                 "wrong number of arguments at line "||SIGL
  285.         when rc2 == 119 then
  286.             err_string = "ERROR 119, "||,
  287.                 "unmatched quotes at line "||SIGL
  288.         when rc2 == 120 then
  289.             err_string = "ERROR 120, "||,
  290.                 "line too long at line "||SIGL
  291.         when rc2 == 236 then
  292.             err_string = "ERROR 236, "||,
  293.                 "unknown command at line "||SIGL
  294.         otherwise
  295.             err_string = "ERROR "||rc2||", at line "||SIGL
  296.         end
  297.         end
  298. else if rc2 == 'RC2' then do
  299.     err_string = "ERROR in command at line "||SIGL
  300.     end
  301. else do
  302.         err_string = rc2||", line "||SIGL
  303.         end
  304.  
  305. request_message TEXT '"'err_string'"'
  306.  
  307. exit
  308.